//
// Created by lzw on 24-10-19.
//

#include <stdio.h>
#include <string.h>
#include "repl.h"
#include "lexer.h"

const char *PROMPT = ">>";

void monkey_repl_start()
{
    char line[1024];
    while (1)
    {
        printf("monkey repl %s", PROMPT);
        fflush(stdout);
        if (!fgets(line, sizeof(line), stdin))
        {
            break;
        }
        struct s_lexer l = new_s_lexer(line);
        while (1)
        {
            struct s_token t = s_lexer_next_token(&l);
            char str[1055];
            s_token_to_str(&t, str);
            printf("%s", str);
            printf("\n");
            if (strcmp(t.type, "MEOF") == 0)
            {
                break;
            }
        }
    }
}